package response

import (
	"encoding/json"

	"gitee.com/shoyer/framework/bizerror/code"
)

// Response Response
type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

// ParseJson ParseJson
func ParseJson(data []byte) (*Response, error) {
	res := &Response{}
	err := json.Unmarshal(data, res)
	if err != nil {
		return nil, err
	}

	return res, nil
}

// IsSuccess IsSuccess
func (r *Response) IsSuccess() bool {
	return r.Code == code.Ok
}
